<script type="text/javascript">
    function checkAll(){
       var checkall=document.getElementsByName('check_all');
       for(var i=0;i<checkall.length;i++)
       {
          checkall[i].checked=true;
       }
    }
    function checkInvert(){
       var checkall=document.getElementsByName('check_all');
       for(var i=0;i<checkall.length;i++)
       {
           if(checkall[i].checked)
                checkall[i].checked=false;
           else
                checkall[i].checked=true;
       }
    }
    function showInfos(contentId){
      $.ajax({type: "POST",url: "<?php echo url_for('user/edit') ?>",data: "userid="+contentId,
                 success: infoResult,error:onfail});
    }
    function onfail(x,e){
        alert("连接失败");
        return false;}
    function infoResult(msg){
        window.open('/index.php/user/home');
    }
    function showDel(contentId){
      $.ajax({type: "POST",url: "<?php echo url_for('user/edit') ?>",data: "duserid="+contentId,
                 success: infoResult,error:onfail});
    }

    function delInfo(content){
        if(confirm('确认要删除？'))
        {
            if(1==content){
                var checkall=document.getElementsByName('check_all');
                content="";
                for(var i=0;i<checkall.length;i++)
                {
                    if(checkall[i].checked)
                        content+=checkall[i].value+" ";
                }
            }
            location="<?php echo url_for("user/index?del=1&content=");  ?>"+content;
        }
    }
</script>
<input id="add" type="button" onclick="window.open('/index.php/user/register')" value="添加用户" />
<input id="del" type="button" onclick="delInfo(1);" value="删除用户" />
<?php
        //echo $aaa;
           echo "<table cellspacing='0' cellpadding='4' border='1' style=\"width:100%;color:#333333;border-collapse:collapse;\">
           <tr style=\"color:White;background-color:#5D7B9D;font-weight:bold;height:25px;\">
           <td style=\"width:50px;\" align=\"center\">ID</td><td style=\"width:30px;\" align=\"center\">选择</td>
           <td align=\"center\" style='width:200px;'>用户名</td><td style=\"width:100px;\" align=\"center\">昵称</td>
           <td style=\"width:70px;\" align=\"center\">真实姓名</td>
           <td style=\"width:80px;\" align=\"center\">注册时间</td><td style=\"width:80px;\" align=\"center\">最近登录时间</td><td style=\"width:70px;\" align=\"center\">操作</td></tr>";
//<table><tr><td>ID</td><td>选择</td><td>用户名</td><td>昵称</td><td>真实姓名</td><td>注册时间</td><td>操作</td></tr>
           $users = @$pages->getResults();
           $i=0;
           foreach($users as $row=>$user)
           {
               if($i%2 == 0)
                   $trStyle = "style=\"color:#333333;background-color:#F7F6F3;height:30px;\"";
               else
                   $trStyle = "style=\"color:#284775;background-color:White;height:30px;\"";
               echo "<tr ".$trStyle."><td>".$user->getUser_id()."</td><td align=\"center\"><input type='checkbox' name='check_all' value='"
                       .$user->getUser_id()."' /></td><td><a href='javascript:showInfos(".$user->getUser_id().")'>".$user->getName()."</a><td>".$user->getNickname()."</td><td>".$user->getReal_name()."</td><td>".date('Y/m/d',strtotime($user->getCreate_time()))
                       ."</td><td>".date('Y/m/d',strtotime($user->getLastLoginTime())) ."</td><td><image border='0' src='/sfDoctrinePlugin/images/edit.png' style='cursor:pointer;' onclick='showInfos(".$user->getUser_id().")'/>"
                       ."<img border='0' title='删除' src='/sfDoctrinePlugin/images/delete.png'onclick='delInfo(".$user->getUser_id().");' style='cursor:pointer;' /></td></tr>";
               $i++;
           }
           echo "</table><input type='button' onclick='checkAll();' value='全选' /> <input type='button' onclick='checkInvert();' value='反选' />";
           $numPages= $pages->getLastPage();
           $CurrentPageID=$pages->getPage();
             if(@$pages->haveToPaginate())
			{
				$str=$CurrentPageID-6;
				$end=$CurrentPageID+5;
				if($str<0)
					$str=0;
				if($end>$numPages)
					$end=$numPages;
				echo "<div class='page_list'>";
				if($CurrentPageID>1)
					echo link_to("首页","user/index?currentPage=1","").link_to("上一页","user/index?currentPage=".($CurrentPageID-1),"");
				 for($i=$str;$i<$end;$i++)
				 {
					if($i==($CurrentPageID-1)){
					echo "<a class='now02' href='#'>".($i+1)."</a>";}
					else{
					    echo link_to(($i+1),"user/index?currentPage=".($i+1),"");
                    }
				 }
				 if($CurrentPageID<$numPages)
				    echo link_to("下一页","user/index?currentPage=".($CurrentPageID+1),"").link_to("末页","user/index?currentPage=".$numPages,"");
				 echo "</div>";
			}
?>
